package com.zzx.controller;

import com.alibaba.fastjson.JSONObject;
import com.zzx.entity.ApiResult;
import com.zzx.entity.TUser;
import com.zzx.service.TUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@Api(tags = "用户 模块管理")
@RestController
@RequestMapping("/TUser")
public class TUserController {

    @Resource
    private TUserService tUserService;

    @ApiOperation(value = "新增、编辑")
    @RequestMapping(value="/add",method = RequestMethod.POST)
    public ApiResult add(@RequestBody TUser param) {
        tUserService.add(param);
        return ApiResult.ok();
    }


    @ApiOperation(value = "删除")
    @RequestMapping(value="/deleteById",method = RequestMethod.POST)
    public ApiResult deleteById(@RequestBody TUser param) {
        tUserService.deleteById(param);
        return ApiResult.ok();
    }

    @ApiOperation(value = "列表查询")
    @RequestMapping(value="/selectBy",method = RequestMethod.POST)
    public ApiResult selectBy(@RequestBody TUser param) {

        return ApiResult.ok(tUserService.selectBy(param));
    }

    @ApiOperation(value = "编辑员工信息和新增公司")
    @RequestMapping(value="/editTUserAndTCompany",method = RequestMethod.POST)
    public ApiResult editTUserAndTCompany(@RequestBody TUser param) {
        JSONObject res = tUserService.editTUserAndTCompany(param);
        return ApiResult.ok(res);
    }

    @ApiOperation(value = "根据ID查询")
    @RequestMapping(value="/findById/{userId}",method = RequestMethod.GET)
    public ApiResult findById(@PathVariable Long userId ) {
        TUser res = tUserService.findById(userId);
        return ApiResult.ok(res);
    }
}
